package com.zhonghui.dolo.manager.config.interceptor;

import com.zhonghui.dolo.manager.model.vo.AdminVo;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class CheckLoginInterceptor extends HandlerInterceptorAdapter {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        // 判断用户是否登录
        AdminVo adminVo = (AdminVo) request.getSession().getAttribute("admin");
        if (adminVo == null) {
            response.sendRedirect("/");
            return false;
        }
        return true;
    }
}
